JBoss Community Archive (Read Only)

PicketBox

Java Keystores

Java ecosystem is equipped with the file based keystores.  "keytool" is the command line interactive tool available to interact with the keystore.

As part of PicketBox, we provide a database backed keystore

A DB backed Keystore is very useful in a clustered environment which rely on a keystore. Instead of relying on a file based keystore at each node in the cluster that needs to be kept in sync, a central DB based Keystore is useful.

We plan to extend this functionality to a full fledged Certificate Management System.

Maven Integration

<dependency>
  <groupId>org.picketbox</groupId>
  <artifactId>picketbox-keystore</artifactId>
  <version>2012aug21</version>
</dependency>

The jar is available from https://repository.jboss.org/nexus/content/groups/public/org/picketbox/picketbox-keystore/2012aug21/picketbox-keystore-2012aug21.jar

The dbkey.sh script is available from: https://github.com/picketbox/picketbox-keystore/blob/master/scripts/dbkey.sh

Instantiating The KeyStore

Provider provider = new PicketBoxKeyStoreDBProvider("PicketBox/Keystore", 1.0, "KeyStore by PicketBox");
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType(), provider);

As you can see, we use the org.picketbox.keystore.PicketBoxKeyStoreDBProvider class as the Keystore provider to the standard keystore instantiation method.

Database Details

You will need to provide a properties file called as "picketbox-keystore-db.properties" on the classpath.

connection.url=jdbc:h2:file:target/test.db
connection.class=org.h2.Driver
connection.username=sa
connection.password=
store.table=STORE
metadata.table=METADATA

The database needs to have two tables  STORE and METADATA with the following structure:

create table STORE (ID varchar(255), KEY varchar(5000), CERT varchar(5000), CHAIN varchar(15000), KEYPASS varchar(150), CREATED varchar(250))

create table METADATA (SALT varchar(255), PASS varchar(5000))

You will need to add an arbitrary string to the column "SALT"  in the METADATA table.

Interactive Tool

We provide interactive command line scripts to interact with the DB based Keystore.

The Tools are:

  • dbkey.sh   (For Unix derived environments including Linux)

  • dbkey.bat  (Not yet available)

    $ ./dbkey.sh
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:4
    Master Password Exists=false
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:6
    Enter Master Salt=xyz
    Enter Master Salt Again=xyz
    Storing Master Salt in the DB
    Stored Master Salt in the DB [1 rows affected]
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:4
    Master Password Exists=false
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:7
    Enter Master Password=
    Enter Master Password Again=
    Master Password stored in DB
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:1
    Enter Keystore URL=jbid_test_keystore.jks
    Enter KeyStore Password=
    Java JKS KeyStore loaded from jbid_test_keystore.jks
    Enter alias=servercert
    Enter Key Password=
    Retrieved Private Key and Certificate from JKS Keystore:jbid_test_keystore.jks
    
    
    
     Enter 1: Import KeyPair
    2: Create a KeyPair and Certificate
    3: Create CSR
    4: Check Master Password Exists
    5: Check Master Salt Exists
    6: Add Master Salt
    7: Add Master Password
    8: Exit
    Enter Your Choice:8
    Good Bye!

The Interactive Tool scripts require the configuration of 3 paths:

  • PicketBox KeyStore Jar.

  • Database Driver

  • BouncyCastle Jars.

You will need to adjust the paths accordingly.

What are the options?

Option 1:  Import a keypair from a regular Java KeyStore.

You will need to provide the keystore url.  Ideally, put the keystore file in the same directory as the dbkey scripts.

Option 2: Create a keypair and certificate

This is the standard keystore functionality. You get to create a keypair in the keystore.

Option 3: Create a Certificate Signing Request (CSR)

When you need to send your certificate for signing to a Certificate Authority (CA), you will need the CSR.  In this, you provide the name of a file where the CSR will be stored.

Option 4: Check Master Password Exists

This is the master keystore password. This option checks whether a master password is stored in the DB.  It depends on the existence of master salt in the database.

Option 5: Check Master Salt Exists

This option checks whether a master salt is stored in the DB.

Option 6: Add Master Salt

If there is no salt saved in the DB, the tool provides a one time opportunity to save a salt. Remember, once it goes into the DB, only a DBA can change/delete a salt.

Option 7: Add Master Password

If the DB has a salt but no master password, the tool provides an option to save a master password.

Need for picketbox-keystore-db.properties

You will need this properties file in the same directory as the dbkey scripts.

connection.url=jdbc:h2:file:target/test.db
connection.class=org.h2.Driver
connection.username=sa
connection.password=
store.table=STORE
metadata.table=METADATA

In this example, I am using the H2Database.

Work To Be Done

  • Interactive Tool needs:

    • Import Certificate Chain.

  • Password Masking in the configuration properties file.

  • Support additional store types such as JCEKS etc.

  • Support JDBC Connection Pooling via Datasource.

Troubleshooting Tips

  • Salt

    • The Salt needs to be added by either the DBA or via the interactive tool. Once the salt exists in the DB, only a DBA can change it. This is done for security reasons.

    • The Salt can only be deleted by a DBA.

  • KeyStore Password (Master Password)

    • Depends on the availability of master salt.

    • Deletion requires DBA assitance.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-11 12:16:32 UTC, last content change 2012-08-21 16:47:46 UTC.